{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "This event loop is already running",
     "output_type": "error",
     "traceback": [
      "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m",
      "\u001B[1;31mRuntimeError\u001B[0m                              Traceback (most recent call last)",
      "Cell \u001B[1;32mIn[1], line 22\u001B[0m\n\u001B[0;32m     20\u001B[0m \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;18m__name__\u001B[39m \u001B[38;5;241m==\u001B[39m \u001B[38;5;124m'\u001B[39m\u001B[38;5;124m__main__\u001B[39m\u001B[38;5;124m'\u001B[39m:\n\u001B[0;32m     21\u001B[0m     loop \u001B[38;5;241m=\u001B[39m asyncio\u001B[38;5;241m.\u001B[39mget_event_loop()\n\u001B[1;32m---> 22\u001B[0m     \u001B[43mloop\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mrun_until_complete\u001B[49m\u001B[43m(\u001B[49m\u001B[43mmain\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\u001B[43m)\u001B[49m\n",
      "File \u001B[1;32mE:\\Anaconda3\\lib\\asyncio\\base_events.py:623\u001B[0m, in \u001B[0;36mBaseEventLoop.run_until_complete\u001B[1;34m(self, future)\u001B[0m\n\u001B[0;32m    612\u001B[0m \u001B[38;5;250m\u001B[39m\u001B[38;5;124;03m\"\"\"Run until the Future is done.\u001B[39;00m\n\u001B[0;32m    613\u001B[0m \n\u001B[0;32m    614\u001B[0m \u001B[38;5;124;03mIf the argument is a coroutine, it is wrapped in a Task.\u001B[39;00m\n\u001B[1;32m   (...)\u001B[0m\n\u001B[0;32m    620\u001B[0m \u001B[38;5;124;03mReturn the Future's result, or raise its exception.\u001B[39;00m\n\u001B[0;32m    621\u001B[0m \u001B[38;5;124;03m\"\"\"\u001B[39;00m\n\u001B[0;32m    622\u001B[0m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39m_check_closed()\n\u001B[1;32m--> 623\u001B[0m \u001B[38;5;28;43mself\u001B[39;49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43m_check_running\u001B[49m\u001B[43m(\u001B[49m\u001B[43m)\u001B[49m\n\u001B[0;32m    625\u001B[0m new_task \u001B[38;5;241m=\u001B[39m \u001B[38;5;129;01mnot\u001B[39;00m futures\u001B[38;5;241m.\u001B[39misfuture(future)\n\u001B[0;32m    626\u001B[0m future \u001B[38;5;241m=\u001B[39m tasks\u001B[38;5;241m.\u001B[39mensure_future(future, loop\u001B[38;5;241m=\u001B[39m\u001B[38;5;28mself\u001B[39m)\n",
      "File \u001B[1;32mE:\\Anaconda3\\lib\\asyncio\\base_events.py:583\u001B[0m, in \u001B[0;36mBaseEventLoop._check_running\u001B[1;34m(self)\u001B[0m\n\u001B[0;32m    581\u001B[0m \u001B[38;5;28;01mdef\u001B[39;00m \u001B[38;5;21m_check_running\u001B[39m(\u001B[38;5;28mself\u001B[39m):\n\u001B[0;32m    582\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m \u001B[38;5;28mself\u001B[39m\u001B[38;5;241m.\u001B[39mis_running():\n\u001B[1;32m--> 583\u001B[0m         \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mRuntimeError\u001B[39;00m(\u001B[38;5;124m'\u001B[39m\u001B[38;5;124mThis event loop is already running\u001B[39m\u001B[38;5;124m'\u001B[39m)\n\u001B[0;32m    584\u001B[0m     \u001B[38;5;28;01mif\u001B[39;00m events\u001B[38;5;241m.\u001B[39m_get_running_loop() \u001B[38;5;129;01mis\u001B[39;00m \u001B[38;5;129;01mnot\u001B[39;00m \u001B[38;5;28;01mNone\u001B[39;00m:\n\u001B[0;32m    585\u001B[0m         \u001B[38;5;28;01mraise\u001B[39;00m \u001B[38;5;167;01mRuntimeError\u001B[39;00m(\n\u001B[0;32m    586\u001B[0m             \u001B[38;5;124m'\u001B[39m\u001B[38;5;124mCannot run the event loop while another loop is running\u001B[39m\u001B[38;5;124m'\u001B[39m)\n",
      "\u001B[1;31mRuntimeError\u001B[0m: This event loop is already running"
     ]
    }
   ],
   "source": [
    "import asyncio\n",
    "from requests_html import HTMLSession\n",
    "\n",
    "async def main():\n",
    "    url = 'https://jobs.51job.com/beijing-cyq/151690627.html?s=sou_sou_soulb&t=0_0&req=d3310cd415ac789e4f3a5075ca48ef9a'\n",
    "\n",
    "    session = HTMLSession()\n",
    "    response = session.get(url)\n",
    "\n",
    "    # 等待5秒钟\n",
    "    await asyncio.sleep(5)\n",
    "\n",
    "    # 在等待时间后再继续处理\n",
    "    # 注意：在实际使用中，请根据网站的加载时间和异步处理的需要进行调整\n",
    "    # 这里只是为了演示在请求后等待一段时间\n",
    "    print(response.content)\n",
    "    msg = response.html.find('div.job_msg')\n",
    "    print(msg)\n",
    "\n",
    "if __name__ == '__main__':\n",
    "    loop = asyncio.get_event_loop()\n",
    "    loop.run_until_complete(main())\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
